<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>SI18n  项目管理</title>
    <meta name="keywords" content="SI18N 项目管理">
    <meta name="description" content="SI18N 项目管理">

    <link href="<?= base_url('assets/css/bootstrap.min.css?v=3.3.6') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/font-awesome.css?v=4.4.0') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/animate.css') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/style.css?v=4.1.0') ?>" rel="stylesheet">

</head>

<body class="gray-bg">

    <div class="wrapper wrapper-content animated fadeInUp">
        <div class="row">
            <div class="col-sm-12">

                <div class="ibox">
                    <div class="ibox-title">
                        <h5>所有项目</h5>
                        <div class="ibox-tools">
                            <a href="<?= base_url('admin/project/add') ?>" class="btn btn-primary btn-xs">创建新项目</a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row m-b-sm m-t-sm">
                            <div class="col-md-1">
                                <button type="button" id="loading-example-btn" class="btn btn-white btn-sm"><i class="fa fa-refresh"></i> 刷新</button>
                            </div>
                            <div class="col-md-11">
                                <div class="input-group">
                                    <input type="text" placeholder="请输入项目名称" class="input-sm form-control"> <span class="input-group-btn">
                                        <button type="button" class="btn btn-sm btn-primary"> 搜索</button> </span>
                                </div>
                            </div>
                        </div>

                        <div class="project-list">

                            <table class="table table-hover">
                                <tbody>
                                
                                <?php foreach ($projects as $project) :?>
                                    <tr>
                                        <td class="project-status">
                                            <h2> <?=$project['name']?></h2>
                                        </td>
                                        <td class="project-title">
                                            <a href="<?= base_url('admin/project/detail?pid='.$project['id']) ?>" ><?=$project['remark']?></a>
                                            <br/>
                                            <small>
                                               <?= TimeUtil::showtime($project["createtime"] , TimeUtil::TIME_ZONE_GMT8) ?>
                                            </small>
                                        </td>
                                        <td class="project-completion">
                                                <small>最后更新</small>
                                            <small>  <?= TimeUtil::showtime($project["updatetime"] , TimeUtil::TIME_ZONE_GMT8) ?></small>
                                        </td>
                                        <td class="project-people">
                                            <small>创建者:</small>
                                            <small><?=$project["username"]?></small>
                                            &nbsp;&nbsp;
                                            <small>我的角色:</small>
                                            <small>
                                                <?= AppConstants::get_project_roleName($project['project_role'])?>
                                            </small>
                                        </td>

                                        <td class="project-actions">
                                            <a href="javascript:open_interpreter(<?=$project['id'] ?>)" class="btn btn-white btn-sm"><i class="fa fa-folder"></i>翻译录入</a>
                                            <a href="<?= base_url('admin/project/detail?pid='.$project['id']) ?>" class="btn btn-white btn-sm"><i class="fa fa-folder"></i> 查看 </a>
                                          <?php if($project['project_role'] != AppConstants::PROJECT_ROLE_INTERPRETER) :?>
                                            <a href="javascript:open_key(<?=$project['id'] ?>)" class="btn btn-white btn-sm"><i class="fa fa-folder"></i>KEY管理 </a>

                                              <?php if($project['project_role'] == AppConstants::PROJECT_ROLE_OWNER) :?>
                                                    <a href="javascript:open_project_dialog(<?=$project['id'] ?>)" class="btn btn-white btn-sm"><i class="fa fa-pencil"></i> 编辑 </a>
                                                    <a href="javascript:deleteProject(<?=$project['id'] ?>, '<?=$project['name']?>')" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> 删除 </a>
                                              <?php endif; ?>

                                           <?php endif; ?>

                                        </td>

                                    </tr>

                                <?php endforeach ?>

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>




    <div class="modal inmodal fade" id="projectModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <form class="m-t" role="form" id="project_edit_form" action="index.html">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                        </button>
                        <h4 class="modal-title">编辑项目</h4>
                    </div>

                    <div class="modal-body">

                        <input type="hidden" name="pid" id="pid" value="">

                        <div class="form-group"><label>项目名称</label>
                            <input type="text" name="pname" id="pname" placeholder="请输入语言名称" class="form-control">
                        </div>



                        <div class="form-group"><label>项目描</label>
                            <textarea  name="remark" id="remark" class="form-control" ></textarea>
                        </div>


                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" id="btn_dlg_lang_submit">保存</button>
                    </div>

                </form>
            </div>
        </div>
    </div>




    <?php include "include/admin_foot_script.php" ?>
    <!-- Data Tables -->
    <script src="<?= base_url('assets/js/plugins/dataTables/jquery.dataTables.js') ?>"></script>
    <script src="<?= base_url('assets/js/plugins/dataTables/dataTables.bootstrap.js') ?>"></script>
    <!-- 自定义js -->
    <script src="<?= base_url('assets/js/content.js?v=1.0.0') ?>"></script>



    <script>

        function open_interpreter(pid) {
            //window.location.href = "<?= base_url('admin/content/data?pid=') ?>" + pid;
           window.open("<?= base_url('admin/content/data?pid=') ?>" + pid, '翻译', 'fullscreen=1, channelmode= 1,location=0, menubar=no');
        }

        function open_key(pid) {

            //window.location.href = "<?= base_url('admin/key/keys?pid=') ?>" + pid;

           window.open("<?= base_url('admin/key/keys?pid=') ?>" + pid, 'KEY', 'fullscreen=1, channelmode= 1,location=0, menubar=no');
        }



        function deleteProject(pid, name) {
            layer.confirm('确认要删除"'+name+'"项目吗？', {
                btn: ['确认','取消'], //按钮
                shade: true, //不显示遮罩,
                shadeClose: true
            }, function(index){
                $.post("<?= base_url("admin/project/delete") ?>", {"pid": pid} ,function (res) {
                    layer.close(index);
                    if (res.code == 200) {
                       window.location.reload();
                    } else {
                        toastr.error(res.msg, '提示');
                    }
                }, "json");
            }, function(){

            });
        }


        $(document).ready(function(){

            $('#loading-example-btn').click(function () {
                btn = $(this);
                simpleLoad(btn, true)

                // Ajax example
//                $.ajax().always(function () {
//                    simpleLoad($(this), false)
//                });

                simpleLoad(btn, false)
            });


            var icon = "<i class='fa fa-times-circle'></i> ";


            $("#project_edit_form").validate({
                rules: {
                    pname: {
                        required: true
                    },
                    remark : {
                        required: true
                    }
                },

                messages: {
                    pname: icon + "请输入项目名称",
                    remark: icon + "请输入项目简介"
                },

                submitHandler: function (form) {
                    var submitData = {
                        "pid": $("#pid").val(),
                        'name': $("#pname").val(),
                        'remark': $("#remark").val()
                    };

                    $.post('<?= base_url("admin/project/update") ?>',
                        submitData,
                        function (res) {
                            if (res.code == 200) {
                                window.location.reload();
                            } else {
                                toastr.error(res.msg, '提示');
                            }
                        }, "json");
                }
            });



        });




        function simpleLoad(btn, state) {
            if (state) {
                btn.children().addClass('fa-spin');
                btn.contents().last().replaceWith(" Loading");
            } else {
                setTimeout(function () {
                    btn.children().removeClass('fa-spin');
                    btn.contents().last().replaceWith(" Refresh");
                }, 2000);
            }
        }


        function open_project_dialog(pid) {
            $("#pid").val(pid);
            $('#langModal .modal-title').html("修改语言");
            $.post("<?= base_url("admin/project/get") ?>", {"pid": pid} ,function (res) {
                $("#pname").val(res.name);
                $("#remark").val(res.remark);
                $('#projectModal').modal('show');
            }, "json");

        }
    </script>

    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script><!--统计代码，可删除-->

    </body>
</html>
